package com.ruoyi.project.stat.paeaReportWorkload.controller;

import java.util.*;

import com.ruoyi.common.enums.WorkloadType;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.stat.paeaReportWorkload.domain.StatisticsWorkloadWrapper;
import com.ruoyi.project.stat.paeaReportWorkload.service.ServiceStatisticsWorkload;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.stat.paeaReportWorkload.domain.PaeaReportWorkload;
import com.ruoyi.project.stat.paeaReportWorkload.service.IStatisticsWorkloadService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * BPO工作量统计Controller
 *
 * @author ruoyi
 * @date 2020-04-11
 */
@Controller
@RequestMapping("/stat/workload")
public class BpoWorkloadStatController extends BaseController
{
    private String prefix = "stat/workload";

    @Autowired
    private IStatisticsWorkloadService statisticsWorkloadService;

    @RequiresPermissions("stat:workload:view")
    @GetMapping()
    public String workload(ModelMap mmap)
    {
        statisticsWorkloadService.init(mmap);
        return prefix + "/workload";
    }

    /**
     * 查询BPO工作量统计列表
     */
    @RequiresPermissions("stat:workload:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list()
    {
        startPage();
        return getDataTable(new ArrayList<PaeaReportWorkload>());
    }
    /**
     * 统计BPO工作量统计列表
     */
    @RequiresPermissions("stat:workload:statistics")
    @PostMapping("/statistics")
    @ResponseBody
    public TableDataInfo statistics(String beginWorkDate,String endWorkDate,String userCode,String orgCode,String workType)
    {
        List<StatisticsWorkloadWrapper> list = statisticsWorkloadService.statistics(beginWorkDate,endWorkDate,userCode,orgCode,workType, ServiceStatisticsWorkload.STATISTICS_BY_BPO);
        return getDataTable(list);
    }
    /**
     * 更新实体信息
     *
     * @param tfxProduct .
     */

    /**
     * 导出BPO工作量统计列表
     */
    @RequiresPermissions("stat:workload:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(String beginWorkDate,String endWorkDate,String userCode,String orgCode,String workType)
    {
        List<StatisticsWorkloadWrapper> list = statisticsWorkloadService.statistics(beginWorkDate,endWorkDate,userCode,orgCode,workType, ServiceStatisticsWorkload.STATISTICS_BY_BPO);
        ExcelUtil<StatisticsWorkloadWrapper> util = new ExcelUtil<StatisticsWorkloadWrapper>(StatisticsWorkloadWrapper.class);
        return util.exportExcel(list, "workload");
    }

    /**
     * 新增BPO工作量统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存BPO工作量统计
     */
    @RequiresPermissions("stat:workload:add")
    @Log(title = "BPO工作量统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaReportWorkload logWorkload)
    {
        return toAjax(statisticsWorkloadService.saveOrUpdate(logWorkload));
    }

    /**
     * 修改BPO工作量统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaReportWorkload logWorkload = statisticsWorkloadService.getById(id);
        mmap.put("logWorkload", logWorkload);
        return prefix + "/edit";
    }

    /**
     * 修改保存BPO工作量统计
     */
    @RequiresPermissions("stat:workload:edit")
    @Log(title = "BPO工作量统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaReportWorkload logWorkload)
    {
        return toAjax(statisticsWorkloadService.saveOrUpdate(logWorkload));
    }
    /**
     * 删除BPO工作量统计
     */
    @RequiresPermissions("stat:workload:remove")
    @Log(title = "BPO工作量统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statisticsWorkloadService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
